package com.person.mengshuai.mytestdemo.controller;

import com.person.mengshuai.mytestdemo.domain.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * redis测试类
 *
 * @author 孟帅
 * @since 2024/7/29
 */
@RestController
@RequestMapping("/redis")
@RefreshScope
public class RedisController {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/set")
    public Result set(@RequestParam String key, @RequestParam String value) {
        redisTemplate.opsForValue().set(key, value);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(@RequestParam String key) {
        Boolean delete = redisTemplate.delete(key);
        return Result.success(delete);
    }

}
